#include <iostream>
#include <vector>
using namespace std;
int n, k;
int main(){
	vector<int> a = { 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
	vector<int> b(13, 0);
	cin >> n >> k;
	int idx = 0, k1 = 0;
	while(a.size() != 2){
	   idx++;
	   k1++;
	   if (idx == a.size()) idx = 1;
	   if (k1 % n == 0){
		   	k1 = 0;
		   	b[idx]++;
		   	if (b[idx] == k) {
		   		a.erase(a.begin() + idx);
		   		b.erase(b.begin() + idx);
		   		idx--;
			}
	   }
	}
	cout << a[1] << endl;

    return 0;
}


